import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    redirect: "/starttotal",
    component: () => import("../views/IndexPage"),
    children: [
      {
        path: "manager",
        name: "manager",
        component: () => import("../views/Manager")
      },
      
      {
        path: "menulist",
        name: "menulist",
        component: () => import("../views/MenuList")
      },
      {
        path: "jurisdiction",
        name: "jurisdiction",
        component: () => import("../views/QuanGroup")
      },
      {
        path: "viplist",
        name: "viplist",
        component: () => import("../views/MemberList")
      },
      {
        path: "navbarlist",
        name: "navbarlist",
        component: () => import("../views/NavbarList")
      },
      {
        path: "newsclass",
        name: "newsclass",
        component: () => import("../views/NewsClass")
      },
      {
        path: "webinfo",
        name: "webinfo",
        component: () => import("../views/WebInfo")
      },
      {
        path: "weblink",
        name: "weblink",
        component: () => import("../views/WebLink")
      },
      {
        path: "schoollist",
        name: "schoollist",
        component: () => import("../views/SchoolList")
      },
      {
        path: "kelist",
        name: "kelist",
        component: () => import("../views/KeList")
      },
      {
        path: "dailist",
        name: "dailist",
        component: () => import("../views/DaList")
      },
      {
        path: "teachers",
        name: "teachers",
        component: () => import("../views/TeachersList")
      },
      {
        path: "artClass",
        name: "artClass",
        component: () => import("../views/ArtClass")
      },
      {
        path: "artlist",
        name: "artlist",
        component: () => import("../views/ArtList")
      },
      {
        path: "artedit/:artid",
        name: "artedit",
        component: () => import("../views/ArtEdit")
      },
      {
        path: "shijuan",
        name: "shijuan",
        component: () => import("../views/ShiJuanList")
      },
      {
        path: "zhangjie",
        name: "zhangjie",
        component: () => import("../views/ZhangJie")
      },
      {
        path: "keclassitem",
        name: "keclassitem",
        component: () => import("../views/KeClassItem")
      },
      {
        path: "singlezhang/:fid",
        name: "singlezhang",
        component: () => import("../views/SingleZhang")
      },
      {
        path: "starttotal",
        name: "starttotal",
        component: () => import("../views/StartTotal")
      },
      {
        path: "datatotal",
        name: "datatotal",
        component: () => import("../views/MyDataTotal")
      },
      {
        path: "ourClass",
        name: "ourClass",
        component: () => import("../views/MyClassList")
      },
      {
        path: "userkelist/:userid",
        name: "userkelist",
        component: () => import("../views/UserKeList")
      },
      {
        path: "freeke",
        name: "freekelist",
        component: () => import("../views/FreeKeList")
      },
      {
        path: "indexbanner",
        name: "indexbanner",
        component: () => import("../views/IndexBanner")
      },
      {
        path: "secondStatic",
        name: "secondStatic",
        component: () => import("../views/SecondStatic")
      },
      {
        path: "secondart",
        name: "secondart",
        component: () => import("../views/SecondArtical")
      },
      {
        path: "secondartedit/:artid",
        name: "secondartedit",
        component: () => import("../views/SecondArtEdit")
      },
      {
        path: "adoutus",
        name: "adoutus",
        component: () => import("../views/AboutUs")
      },
      {
        path: "adoutuslist/:id",
        name: "adoutuslist",
        component: () => import("../views/AboutEdit")
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("../views/Login"),
    
  },
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let token = localStorage.token
  let path = to.path
  if(!token && path != "/login") {
    next("/login")
  } else {
    next()
  }
})

export default router
